﻿<%@ Application Language="C#" %>
<%@ Import Namespace="System.Timers" %>
<%@ Import Namespace=" System.Collections.Generic" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="Data" %>
<script RunAt="server">


    void Application_Start(object sender, EventArgs e)
    {
        System.Timers.Timer objTimer = new System.Timers.Timer();
        objTimer.Interval = 1000 * 1 * 1; //这个时间单位毫秒,比如10秒，就写10000 86400000
        objTimer.Enabled = true;
        objTimer.Elapsed += new ElapsedEventHandler(objTimer_Elapsed);

        //System.Timers.Timer objTimer1 = new System.Timers.Timer();
        //objTimer1.Interval = 1000 * 1 * 1;
        //objTimer1.Enabled = true;
        //objTimer1.Elapsed += new ElapsedEventHandler(objTimer1_Elapsed);

        System.Timers.Timer objTimer2 = new System.Timers.Timer();
        objTimer2.Interval = 1000 * 60 * 60;
        objTimer2.Enabled = true;
        objTimer2.Elapsed += new ElapsedEventHandler(ComputeMediaForecaststatistics);

        System.Timers.Timer objTimer3 = new System.Timers.Timer();
        objTimer3.Interval = 1000 * 60 * 60;
        objTimer3.Enabled = true;
        objTimer3.Elapsed += new ElapsedEventHandler(GetPageInfo);

    }
    void objTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        string strweek = e.SignalTime.DayOfWeek.ToString();
        int inthour = e.SignalTime.Hour;
        int intminute = e.SignalTime.Minute;
        int intSecond = e.SignalTime.Second;
        int ihour = 00;
        int iminute = 01;
        int iSecond = 00;
        if (inthour == ihour && intminute == iminute && intSecond == iSecond)
        {
            #region 自动生成每种彩票的期数
            int totalCount = 0;
            //更新每种彩票的期数
            List<Model.LotteryQs> lotteryQs = BLL.LotteryQs.GetPageList_Where(0, int.MaxValue, 0, out totalCount);
            for (int i = 0; i < lotteryQs.Count; i++)
            {
                string qs = "";
                int week = selectNextDate(DateTime.Now);
                DateTime timer = new DateTime();
                DateTime pre_opentime = new DateTime();
                if (lotteryQs[i].LotteryType == 1)//2，4，7开奖
                {
                    if (week == 1 || week == 3 || week == 5)//双色球
                    {
                        qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                        timer = DateTime.Now;
                        if (week == 1 || week == 3)
                        {
                            pre_opentime = timer.AddDays(1).AddHours(19).AddMinutes(30);
                        }
                        else if (week == 5)
                        {
                            pre_opentime = timer.AddDays(2).AddHours(19).AddMinutes(30);
                        }

                    }
                }
                else if (lotteryQs[i].LotteryType == 2)//大乐透
                {
                    if (week == 2 || week == 4 || week == 7)//1，3，6 开奖
                    {
                        if (week == 2 || week == 7)
                        {
                            qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                            timer = DateTime.Now;
                            pre_opentime = timer.AddDays(1).AddHours(19).AddMinutes(30);
                        }
                        else if (week == 4)
                        {
                            qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                            timer = DateTime.Now;
                            pre_opentime = timer.AddDays(2).AddHours(19).AddMinutes(30);
                        }

                    }
                }
                else if (lotteryQs[i].LotteryType == 3)//排列三
                {
                    qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                    timer = DateTime.Now;
                    pre_opentime = timer.AddMinutes(19).AddMinutes(30);
                }
                else if (lotteryQs[i].LotteryType == 4)//排列五
                {
                    qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                    timer = DateTime.Now;
                    pre_opentime = timer.AddHours(19).AddMinutes(30);
                }
                else if (lotteryQs[i].LotteryType == 5)//福彩3D
                {
                    qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                    timer = DateTime.Now;
                    pre_opentime = timer.AddHours(19).AddMinutes(30);
                }
                else if (lotteryQs[i].LotteryType == 6)//七星彩
                {
                    if (week == 3 || week == 6 || week == 1)//2,5,7开奖
                    {
                        if (week == 1 || week == 6)
                        {
                            qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                            timer = DateTime.Now;
                            pre_opentime = timer.AddDays(1).AddHours(19).AddMinutes(30);
                        }
                        else if (week == 3)
                        {
                            qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                            timer = DateTime.Now;
                            pre_opentime = timer.AddDays(2).AddHours(19).AddMinutes(30);
                        }

                    }

                }
                else if (lotteryQs[i].LotteryType == 7)//七乐彩 1,3,5开奖
                {
                    if (week == 2 || week == 4 || week == 6)
                    {
                        qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                        timer = DateTime.Now;
                        pre_opentime = timer.AddDays(1).AddHours(19).AddMinutes(30);
                    }
                    else if (week == 6)
                    {
                        qs = (int.Parse(lotteryQs[i].Lotteryqs) + 1).ToString();
                        timer = DateTime.Now;
                        pre_opentime = timer.AddDays(2).AddHours(19).AddMinutes(30);
                    }
                }
                Model.LotteryQs modelQs = BLL.LotteryQs.GetModel(lotteryQs[i].id);
                modelQs.Lotteryqs = qs;
                modelQs.StartTime = timer;
                modelQs.pre_opentime = pre_opentime;
                if (timer != new DateTime())
                {
                    BLL.LotteryQs.Update(modelQs);
                }

            }
            #endregion
        }
    }
    //void objTimer1_Elapsed(object sender, ElapsedEventArgs e)
    //{
    //    string strweek = e.SignalTime.DayOfWeek.ToString();
    //    int inthour = e.SignalTime.Hour;
    //    int intminute = e.SignalTime.Minute;
    //    int intSecond = e.SignalTime.Second;
    //    //string sweek = "Thursday";
    //    int ihour = 01;
    //    int iminute = 00;
    //    int iSecond = 00;
    //    if (inthour == ihour && intSecond == iSecond && intminute == iminute)
    //    {
    //        GetLotterAccouncement();//自动获取开奖信息并写入数据库
    //    }
    //}

    void ComputeMediaForecaststatistics(object sender, ElapsedEventArgs e)
    {
        BLL.MediaForecast.UpdateForecast();//开奖后，更新媒体预测数据
    }

    #region
    /// <summary>
    /// 获取开奖信息并写入数据库
    /// </summary>

    //public void GetLotterAccouncement()
    //{
    //    string url = "http://apis.baidu.com/apistore/lottery/lotteryquery";
    //    int totalCount2 = 0;

    //    List<Model.Lottery> arlist = BLL.Lottery.GetPageList_Where(0, int.MaxValue, 0, out totalCount2);

    //    string type = string.Empty;
    //    for (int i = 0; i < arlist.Count; i++)
    //    {
    //        int typeid = arlist[i].id;

    //        if (i == 0)
    //        {
    //            type = "ssq";

    //        }
    //        if (i == 1)
    //        {
    //            type = "dlt";
    //        }
    //        if (i == 2)
    //        {
    //            type = "pl3";
    //        }
    //        if (i == 3)
    //        {
    //            type = "pl5";
    //        }
    //        if (i == 4)
    //        {
    //            type = "fc3d";
    //        }
    //        if (i == 5)
    //        {
    //            type = "qxc";
    //        }
    //        if (i == 6)
    //        {
    //            type = "qlc";
    //        }

    //        string param = "lotterycode=" + type + "&recordcnt=20";
    //        LitJson.JsonData getdata = LitJson.JsonMapper.ToObject(requestData(url, param));
    //        LitJson.JsonData errNum = getdata["errNum"];
    //        LitJson.JsonData retMsg = getdata["retMsg"];
    //        if (int.Parse(errNum.ToString()) == 0 && retMsg.ToString() == "success")
    //        {
    //            LitJson.JsonData data_retData = getdata["retData"]["data"];
    //            int itemCnt = data_retData.Count;//获取到的个数
    //            foreach (LitJson.JsonData item in data_retData)  // 遍历数组 items             
    //            {
    //                string expect = item["expect"].ToString();
    //                string openCode = item["openCode"].ToString();
    //                string openTime = item["openTime"].ToString();

    //                Model.LotteryAnnouncement models = new Model.LotteryAnnouncement();
    //                models.AddTime = DateTime.Now;
    //                models.LotteryType = typeid;
    //                models.LotteryQS = expect;
    //                models.LotteryNo = openCode;
    //                models.openTime = Convert.ToDateTime(openTime);
    //                SqlParameter[] p = {
    //                            new SqlParameter("@AddTime",models.AddTime),
    //                            new SqlParameter("@LotteryType",models.LotteryType),
    //                            new SqlParameter("@LotteryQS",models.LotteryQS),
    //                            new SqlParameter("@LotteryNo",models.LotteryNo),
    //                            new SqlParameter("@openTime",models.openTime)
    //                           };
    //                string Sql = "Insert into [LotteryAnnouncement] ([AddTime],[LotteryType],[LotteryQS],[LotteryNo],[oneCount],[oneMoney],[twoCount],[twoMoney],[threeCount],[threeMoney],[fourCount],[fourMoney],[fiveCount],[fiveMoney],[sixCount],[sixMoney],[twoSCount],[twoSMoney],[openTime]) ";
    //                Sql += " Select @AddTime, @LotteryType, @LotteryQS, @LotteryNo,0,0,0,0,0,0,0,0,0,0,0,0,0,0,@openTime ";
    //                Sql += " Where (Select count(id) from LotteryAnnouncement where LotteryType = @LotteryType and LotteryQS = @LotteryQS and LotteryNo=@LotteryNo and openTime=@openTime)= 0";
    //                if (DbHelp.ExecuteNonQuery(DBConfig.ConnectionSettings, CommandType.Text, Sql, p) <= 0)
    //                {
    //                    //开奖信息表添加不成功，添加入开奖信息遗漏表中
    //                    string sql = "Insert into LotteryAccouncement_MissingData ([AddTime],[LotteryType],[LotteryQS],[LotteryNo],[openTime],[createtime]) values (@AddTime, @LotteryType, @LotteryQS, @LotteryNo,@openTime," + DateTime.Now + ") ";
    //                    DbHelp.ExecuteNonQuery(DBConfig.ConnectionSettings, CommandType.Text, sql, p);
    //                }

    //            }
    //        }
    //        else
    //        {
    //            throw new System.Exception("insert wrong!");
    //            //获取失败
    //        }

    //    }

    //}
    /// <summary>
    /// 发送HTTP请求,从官网获取最新彩票出奖情况
    /// </summary>
    /// <param name="url">请求的URL</param>
    /// <param name="param">请求的参数</param>
    /// <returns>请求结果</returns>
    //public static string requestData(string url, string param)
    //{
    //    string strURL = url + '?' + param;
    //    System.Net.HttpWebRequest request;
    //    request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
    //    request.Method = "GET";
    //    // 添加header
    //    request.Headers.Add("apikey", "80a0e31c2895f371d624c3a3995350ab");//这是客户提供的API
    //    System.Net.HttpWebResponse response;
    //    response = (System.Net.HttpWebResponse)request.GetResponse();
    //    System.IO.Stream s;
    //    s = response.GetResponseStream();
    //    string StrDate = "";
    //    string strValue = "";
    //    StreamReader Reader = new StreamReader(s, Encoding.UTF8);
    //    while ((StrDate = Reader.ReadLine()) != null)
    //    {
    //        strValue += StrDate + "\r\n";
    //    }
    //    return strValue;
    //}
    #endregion

    /// <summary>
    /// 计算星期几
    /// </summary>
    /// <param name="weekinfo"></param>
    /// <returns></returns>
    private int selectNextDate(DateTime timer)
    {
        int week = -1;
        string weekstr = timer.DayOfWeek.ToString();
        if (weekstr.Equals("Monday"))
        {
            week = 1;
        }
        else if (weekstr.Equals("Tuesday"))
        {
            week = 2;
        }
        else if (weekstr.Equals("Wednesday"))
        {
            week = 3;
        }
        else if (weekstr.Equals("Thursday"))
        {
            week = 4;
        }
        else if (weekstr.Equals("Friday"))
        {
            week = 5;
        }
        else if (weekstr.Equals("Saturday"))
        {
            week = 6;
        }
        else if (weekstr.Equals("Sunday"))
        {
            week = 7;
        }
        return week;
    }





    void Application_End(object sender, EventArgs e)
    {
        //在应用程序关闭时运行的代码
        //下面的代码是关键，可解决IIS应用程序池自动回收的问题
        System.Threading.Thread.Sleep(1000);
        //这里设置你的web地址，可以随便指向你的任意一个aspx页面甚至不存在的页面，目的是要激发Application_Start

        string url = "http://sfrrb.com";
        System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
        System.Net.HttpWebResponse myHttpWebResponse = (System.Net.HttpWebResponse)myHttpWebRequest.GetResponse();
        System.IO.Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流

    }

    void Application_Error(object sender, EventArgs e)
    {
        //Exception err = Server.GetLastError();
        ////在出现未处理的错误时运行的代码
        //string errInfo = err.Message;
        //string log = "Time:" + System.DateTime.Now.ToString() + "\r\nIP:" + Request.UserHostAddress + "\r\nUrl:";
        //log += Request.Url.ToString() + "\r\nInfo:" + errInfo + "\r\nSource:" + err.Source + "\r\n";    // StackTrace:" + err.StackTrace + "\r\n";

        ////清除前一个异常  

        //Server.ClearError();

        ////独占方式，因为文件只能由一个进程写入.
        //System.IO.StreamWriter writer = null;
        //try
        //{
        //    lock (this)
        //    {
        //        // 写入日志
        //        string year = DateTime.Now.Year.ToString();
        //        string month = DateTime.Now.Month.ToString();
        //        string path = string.Empty;
        //        string filename = DateTime.Now.Day.ToString() + ".log";
        //        path = Server.MapPath("~/ErrorLog/") + year + "." + (month.Length < 2 ? "0" + month.ToString() : month.ToString());
        //        // 如果目录不存在则创建
        //        if (!System.IO.Directory.Exists(path))
        //        {
        //            System.IO.Directory.CreateDirectory(path);
        //        }
        //        System.IO.FileInfo file = new System.IO.FileInfo(path + "/" + filename);


        //        // 文件不存在就创建,true表示追加

        //        writer = new System.IO.StreamWriter(file.FullName, true);
        //        writer.WriteLine(log);
        //    }
        //}
        //finally
        //{
        //    if (writer != null)
        //        writer.Close();

        //}

        //System.Web.HttpContext.Current.Response.Redirect("~/ErrorPage.aspx?Info=" + Server.UrlEncode(errInfo));

    }

    void Session_Start(object sender, EventArgs e)
    {
        //在新会话启动时运行的代码

    }

    void Session_End(object sender, EventArgs e)
    {
        //在会话结束时运行的代码。 
        // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
        // InProc 时，才会引发 Session_End 事件。如果会话模式 
        //设置为 StateServer 或 SQLServer，则不会引发该事件。

    }
    void GetPageInfo(object sender, ElapsedEventArgs e)
    {
        //httpPost1("http://cp.360.cn/kj/ssq.html?src=menu&r_a=UVzQ32", 1);
        //httpPost2("http://cp.360.cn/kj/slt.html?src=menu&r_a=Jfqqim", 2);
        //httpPost3("http://cp.360.cn/kj/sd.html?src=menu&r_a=MjQVRz", 5);
        //httpPost3("http://cp.360.cn/kj/p3.html?r_a=muaEnu", 3);
        //httpPost4("http://cp.360.cn/kj/p5.html?r_a=MriAB3", 4);
        //httpPost5("http://cp.360.cn/kj/qxc.html?r_a=YbaQN3", 6);
        //httpPost6("http://cp.360.cn/kj/qlc.html?r_a=Fzaeme", 7);

        GetHtmlEx("http://www.17500.cn/getData/ssq.TXT", Encoding.UTF8, 1);
        GetHtmlEx("http://www.17500.cn/getData/dlt.TXT", Encoding.UTF8, 2);
        GetHtmlEx("http://www.17500.cn/getData/p3.TXT", Encoding.UTF8, 3);
        GetHtmlEx("http://www.17500.cn/getData/p5.TXT", Encoding.UTF8, 4);
        GetHtmlEx("http://www.17500.cn/getData/3d.TXT", Encoding.UTF8, 5);
        GetHtmlEx("http://www.17500.cn/getData/7xc.TXT", Encoding.UTF8, 6);
        GetHtmlEx("http://www.17500.cn/getData/7lc.TXT", Encoding.UTF8, 7);
    }

    private void GetHtmlEx(string url, Encoding encoding, int type)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*";
        request.Method = "get";
        request.AllowAutoRedirect = false;
        request.Timeout = 50000;

        WebResponse response = request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream, encoding);
        String html = reader.ReadToEnd();//全部读出来

        string[] allLines;
        if (type == 1)
        {
            string filePath = Server.MapPath(@"\App_Data\ssq.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\ssq.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 1);
        }
        else if (type == 2)
        {
            string filePath = Server.MapPath(@"\App_Data\dlt.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\dlt.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 2);
        }
        else if (type == 3)
        {
            string filePath = Server.MapPath(@"\App_Data\p3.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\p3.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 3);
        }
        else if (type == 4)
        {
            string filePath = Server.MapPath(@"\App_Data\p5.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\p5.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 4);
        }
        else if (type == 5)
        {
            string filePath = Server.MapPath(@"\App_Data\3d.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\3d.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 5);
        }
        else if (type == 6)
        {
            string filePath = Server.MapPath(@"\App_Data\7xc.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\7xc.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 6);
        }
        else if (type == 7)
        {
            string filePath = Server.MapPath(@"\App_Data\7lc.txt");
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空了。
            sw.Write(html);//写字符串。
            sw.Close();
            response.Close();
            allLines = File.ReadAllLines(Server.MapPath(@"\App_Data\7lc.txt"));
            string[] newdata = allLines[allLines.Length - 1].Split(' ');//最新一条数据开奖数据
            GetModel(newdata, 7);
        }



    }

    private void GetModel(string[] data, int type)
    {

        if (type == 1)
        {
            #region 双色球
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 1;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4] + "," + data[5] + "," + data[6] + "," + data[7] + "+" + data[8];
            model.AppearOrderNo = data[9] + "," + data[10] + "," + data[11] + "," + data[12] + "," + data[13] + "," + data[14];
            model.sumMoney = decimal.Parse(data[15]);
            model.jiangChi = decimal.Parse(data[16]);
            model.oneCount = int.Parse(data[17]);
            model.oneMoney = decimal.Parse(data[18]);
            model.twoCount = int.Parse(data[19]);
            model.twoMoney = decimal.Parse(data[20]);
            model.threeCount = int.Parse(data[21]);
            model.threeMoney = decimal.Parse(data[22]);
            model.fourCount = int.Parse(data[23]);
            model.fourMoney = decimal.Parse(data[24]);
            model.fiveCount = int.Parse(data[25]);
            model.fiveMoney = decimal.Parse(data[26]);
            model.sixCount = int.Parse(data[27]);
            model.sixMoney = decimal.Parse(data[28]);
            addWinInfo(model);
            #endregion
        }
        else if (type == 2)
        {
            #region 大乐透
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 2;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4] + "," + data[5] + "," + data[6] + "+" + data[7] + "," + data[8];
            model.AppearOrderNo = "0";
            model.sumMoney = decimal.Parse(data[9]);
            model.jiangChi = decimal.Parse(data[10]);
            model.oneCount = int.Parse(data[11]);
            model.oneMoney = decimal.Parse(data[12]);
            model.twoCount = int.Parse(data[13]);
            model.twoMoney = decimal.Parse(data[14]);
            model.threeCount = int.Parse(data[15]);
            model.threeMoney = decimal.Parse(data[16]);
            model.fourCount = int.Parse(data[17]);
            model.fourMoney = decimal.Parse(data[18]);
            model.fiveCount = int.Parse(data[19]);
            model.fiveMoney = decimal.Parse(data[20]);
            model.sixCount = int.Parse(data[21]);
            model.sixMoney = decimal.Parse(data[22]);
            addWinInfo(model);
            #endregion
        }
        else if (type == 3)
        {
            #region 排三
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 3;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4];//开奖号码
            model.AppearOrderNo = "0";
            model.sumMoney = decimal.Parse(data[5]);
            model.jiangChi = 0;
            model.oneCount = int.Parse(data[6]);
            model.oneMoney = decimal.Parse(data[7]);
            model.twoCount = int.Parse(data[8]);
            model.twoMoney = decimal.Parse(data[9]);
            model.threeCount = int.Parse(data[10]);
            model.threeMoney = decimal.Parse(data[11]);
            model.fourCount = 0;
            model.fourMoney = 0;
            model.fiveCount = 0;
            model.fiveMoney = 0;
            model.sixCount = 0;
            model.sixMoney = 0;
            addWinInfo(model);
            #endregion
        }
        else if (type == 4)
        {
            #region 排五
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 4;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4] + "," + data[5];//开奖号码
            model.AppearOrderNo = "0";
            model.sumMoney = decimal.Parse(data[6]);
            model.jiangChi = 0;
            model.oneCount = int.Parse(data[7]);
            model.oneMoney = decimal.Parse(data[8]);
            model.twoCount = 0;
            model.twoMoney = 0;
            model.threeCount = 0;
            model.threeMoney = 0;
            model.fourCount = 0;
            model.fourMoney = 0;
            model.fiveCount = 0;
            model.fiveMoney = 0;
            model.sixCount = 0;
            model.sixMoney = 0;
            addWinInfo(model);
            #endregion
        }
        else if (type == 5)
        {
            #region 福彩3D
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 5;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4];//开奖号码
            model.AppearOrderNo = data[5] + "," + data[6] + "," + data[7] + "+" + data[8] + "," + data[9];//试机号+机球
            model.sumMoney = decimal.Parse(data[10]);
            model.jiangChi = 0;
            model.oneCount = int.Parse(data[11]);
            model.oneMoney = decimal.Parse(data[12]);
            model.twoCount = int.Parse(data[13]);
            model.twoMoney = decimal.Parse(data[14]);
            model.threeCount = int.Parse(data[15]);
            model.threeMoney = decimal.Parse(data[16]);
            model.fourCount = 0;
            model.fourMoney = 0;
            model.fiveCount = 0;
            model.fiveMoney = 0;
            model.sixCount = 0;
            model.sixMoney = 0;
            addWinInfo(model);
            #endregion
        }
        else if (type == 6)
        {
            #region 七星彩
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 6;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4] + "," + data[5] + "," + data[6] + "," + data[7] + "," + data[8];
            model.AppearOrderNo = "0";
            model.sumMoney = decimal.Parse(data[9]);
            model.jiangChi = decimal.Parse(data[10]);
            model.oneCount = int.Parse(data[11]);
            model.oneMoney = decimal.Parse(data[12]);
            model.twoCount = int.Parse(data[13]);
            model.twoMoney = decimal.Parse(data[14]);
            model.threeCount = int.Parse(data[15]);
            model.threeMoney = decimal.Parse(data[16]);
            model.fourCount = int.Parse(data[17]);
            model.fourMoney = decimal.Parse(data[18]);
            model.fiveCount = int.Parse(data[19]);
            model.fiveMoney = decimal.Parse(data[20]);
            model.sixCount = int.Parse(data[21]);
            model.sixMoney = decimal.Parse(data[22]);
            addWinInfo(model);
            #endregion
        }
        else if (type == 7)
        {
            #region 七乐彩
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            model.AddTime = System.DateTime.Now;
            model.LotteryType = 7;
            model.LotteryQS = data[0];
            model.openTime = DateTime.Parse(data[1]);
            model.LotteryNo = data[2] + "," + data[3] + "," + data[4] + "," + data[5] + "," + data[6] + "," + data[7] + "," + data[8] + "+" + data[9];
            model.AppearOrderNo = "0";
            model.sumMoney = decimal.Parse(data[10]);
            model.jiangChi = decimal.Parse(data[11]);
            model.oneCount = int.Parse(data[12]);
            model.oneMoney = decimal.Parse(data[13]);
            model.twoCount = int.Parse(data[14]);
            model.twoMoney = decimal.Parse(data[15]);
            model.threeCount = int.Parse(data[16]);
            model.threeMoney = decimal.Parse(data[17]);
            model.fourCount = int.Parse(data[18]);
            model.fourMoney = decimal.Parse(data[19]);
            model.fiveCount = int.Parse(data[20]);
            model.fiveMoney = decimal.Parse(data[21]);
            model.sixCount = int.Parse(data[22]);
            model.sixMoney = decimal.Parse(data[23]);
            model.sevenCount = int.Parse(data[24]);
            model.sevenMoney = decimal.Parse(data[25]);
            addWinInfo(model);
            #endregion
        }

    }

    public void httpPost1(string url, int lotteryType)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*";
        request.Timeout = 50000;
        request.AllowAutoRedirect = false;
        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;
        try
        {
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Close();

            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                responseStr = reader.ReadToEnd();
                int startIndex = responseStr.IndexOf("codeshow");
                int endIndex = responseStr.IndexOf("</ul >");
                string LotteryNo = responseStr.Substring(startIndex + 11, endIndex - startIndex - 11);  //截取内容               
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "<[^>]+>", "");
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "&[^;]+;", "").Trim();
                model.LotteryNo = LotteryNo.Substring(0, 2) + "," + LotteryNo.Substring(2, 2) + "," + LotteryNo.Substring(4, 2) + "," + LotteryNo.Substring(6, 2) + "," + LotteryNo.Substring(8, 2) + "," + LotteryNo.Substring(10, 2) + "+" + LotteryNo.Substring(12, 2);//中奖号码
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "<[^>]+>", "");
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "&[^;]+;", "").Trim();
                endIndex = responseStr.IndexOf("期");
                string temp = responseStr.Substring(7, endIndex - 7);  //截取内容         
                model.LotteryQS = temp;
                endIndex = responseStr.IndexOf("按期号查询");
                string openTime = responseStr.Substring(endIndex - 200, 300).Trim();
                startIndex = openTime.IndexOf("期");
                endIndex = openTime.IndexOf("按");
                openTime = openTime.Substring(startIndex + 1, endIndex - startIndex - 1).Trim();
                startIndex = openTime.IndexOf("(");
                string part1 = openTime.Substring(0, startIndex - 1).Trim();
                startIndex = openTime.IndexOf(")");
                string part2 = openTime.Substring(startIndex + 1).Trim();
                model.openTime = Convert.ToDateTime(part1 + " " + part2);
                startIndex = responseStr.IndexOf("一等奖");
                endIndex = responseStr.IndexOf("二等奖");
                temp = responseStr.Substring(startIndex + 6, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.oneCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//一等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.oneMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("6+0");
                endIndex = responseStr.IndexOf("三等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.twoCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//二等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.twoMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("5+1");
                endIndex = responseStr.IndexOf("四等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.threeCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//三等奖个数
                startIndex = responseStr.IndexOf("4+1");
                endIndex = responseStr.IndexOf("五等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fourCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//四等奖个数
                startIndex = responseStr.IndexOf("3+1");
                endIndex = responseStr.IndexOf("六等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fiveCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//五等奖个数
                startIndex = responseStr.IndexOf("0+1");
                temp = responseStr.Substring(startIndex + 3, 100);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.sixCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//六等奖个数
                startIndex = responseStr.IndexOf("投注总额");
                endIndex = responseStr.IndexOf("奖池累计");
                temp = responseStr.Substring(startIndex + 5, endIndex - startIndex - 8);  //截取内容  
                endIndex = temp.IndexOf("元");
                model.sumMoney = Convert.ToDecimal(temp.Substring(0, endIndex - 1).Trim(','));  //投注总额    
                startIndex = responseStr.IndexOf("奖池累计");
                string jiangChi = responseStr.Substring(startIndex + 5, 50);  //截取内容    
                endIndex = jiangChi.IndexOf("元");
                if (endIndex != -1)
                {
                    model.jiangChi = Convert.ToDecimal(jiangChi.Substring(0, endIndex - 1).Trim(','));  //截取内容  
                }
                else
                {
                    model.jiangChi = 0;
                }
                model.LotteryType = lotteryType;
                model.threeMoney = 3000;
                model.fourMoney = 200;
                model.fiveMoney = 10;
                model.sixMoney = 5;
                if (model.sixCount > 0)
                {
                    addWinInfo(model);
                }
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }
    }
    public void httpPost2(string url, int lotteryType)
    {

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*/*";
        request.Timeout = 50000;
        request.AllowAutoRedirect = false;

        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;

        try
        {
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Close();
            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                responseStr = reader.ReadToEnd();
                int startIndex = responseStr.IndexOf("codeshow");
                int endIndex = responseStr.IndexOf("</ul >");
                string LotteryNo = responseStr.Substring(startIndex + 11, endIndex - startIndex - 11);  //截取内容               
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "<[^>]+>", "");
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "&[^;]+;", "").Trim();
                model.LotteryNo = LotteryNo.Substring(0, 2) + "," + LotteryNo.Substring(2, 2) + "," + LotteryNo.Substring(4, 2) + "," + LotteryNo.Substring(6, 2) + "," + LotteryNo.Substring(8, 2) + "+" + LotteryNo.Substring(10, 2) + "," + LotteryNo.Substring(12, 2);//中奖号码
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "<[^>]+>", "");
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "&[^;]+;", "").Trim();
                endIndex = responseStr.IndexOf("期");
                string temp = responseStr.Substring(7, endIndex - 7);  //截取内容         
                model.LotteryQS = temp;
                endIndex = responseStr.IndexOf("按期号查询");
                string openTime = responseStr.Substring(endIndex - 200, 300).Trim();
                startIndex = openTime.IndexOf("期");
                endIndex = openTime.IndexOf("按");
                openTime = openTime.Substring(startIndex + 1, endIndex - startIndex - 1).Trim();
                startIndex = openTime.IndexOf("(");
                string part1 = openTime.Substring(0, startIndex - 1).Trim();
                startIndex = openTime.IndexOf(")");
                string part2 = openTime.Substring(startIndex + 1).Trim();
                model.openTime = Convert.ToDateTime(part1 + " " + part2);//开奖时间
                startIndex = responseStr.IndexOf("5+2");
                endIndex = responseStr.IndexOf("二等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.oneCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//一等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.oneMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));

                startIndex = responseStr.IndexOf("5+1");
                endIndex = responseStr.IndexOf("三等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.twoCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//二等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.twoMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("4+2");
                endIndex = responseStr.IndexOf("四等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.threeCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//三等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.threeMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("3+2");
                endIndex = responseStr.IndexOf("五等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fourCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//四等奖个数
                startIndex = responseStr.IndexOf("2+2");
                endIndex = responseStr.IndexOf("六等奖");
                temp = responseStr.Substring(startIndex + 3, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fiveCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//五等奖个数
                startIndex = responseStr.IndexOf("0+2");
                temp = responseStr.Substring(startIndex + 3, 100);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.sixCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//六等奖个数
                startIndex = responseStr.IndexOf("投注总额");
                endIndex = responseStr.IndexOf("奖池累计");
                temp = responseStr.Substring(startIndex + 5, endIndex - startIndex - 8);  //截取内容  
                endIndex = temp.IndexOf("元");
                model.sumMoney = Convert.ToDecimal(temp.Substring(0, endIndex - 1).Trim(','));  //投注总额    
                startIndex = responseStr.IndexOf("奖池累计");
                string jiangChi = responseStr.Substring(startIndex + 5, 50);  //截取内容    
                endIndex = jiangChi.IndexOf("元");
                if (endIndex != -1)
                {
                    jiangChi = jiangChi.Substring(0, endIndex - 1);  //截取内容  
                }
                else
                {
                    jiangChi = "0";
                }
                model.fourMoney = 200;
                model.fiveMoney = 10;
                model.sixMoney = 5;
                model.LotteryType = lotteryType;
                if (model.sixCount > 0)
                {
                    addWinInfo(model);
                }
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }
    }
    public void httpPost3(string url, int lotteryType)
    {

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*/*";
        request.Timeout = 50000;
        request.AllowAutoRedirect = false;

        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;

        try
        {
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Close();
            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                responseStr = reader.ReadToEnd();
                int startIndex = responseStr.IndexOf("codeshow");
                int endIndex = responseStr.IndexOf("</ul >");
                string LotteryNo = responseStr.Substring(startIndex + 11, endIndex - startIndex - 11);  //截取内容               
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "<[^>]+>", "");
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "&[^;]+;", "").Trim();
                model.LotteryNo = LotteryNo.Substring(0, 1) + "," + LotteryNo.Substring(1, 1) + "," + LotteryNo.Substring(2, 1);//中奖号码
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "<[^>]+>", "");
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "&[^;]+;", "").Trim();
                endIndex = responseStr.IndexOf("期");
                string temp = lotteryType == 5 ? responseStr.Substring(8, endIndex - 8) : responseStr.Substring(7, endIndex - 7);  //截取内容         
                model.LotteryQS = temp;
                endIndex = responseStr.IndexOf("按期号查询");
                string openTime = responseStr.Substring(endIndex - 200, 300).Trim();
                startIndex = openTime.IndexOf("期");
                endIndex = openTime.IndexOf("按");
                openTime = openTime.Substring(startIndex + 1, endIndex - startIndex - 1).Trim();
                startIndex = openTime.IndexOf("(");
                string part1 = openTime.Substring(0, startIndex - 1).Trim();
                startIndex = openTime.IndexOf(")");
                string part2 = openTime.Substring(startIndex + 1).Trim();
                model.openTime = Convert.ToDateTime(part1 + " " + part2);//开奖时间
                startIndex = responseStr.IndexOf("与开奖号相同且顺序一致");
                endIndex = responseStr.IndexOf("组选3");
                temp = responseStr.Substring(startIndex + 11, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.oneCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//一等奖个数
                startIndex = responseStr.IndexOf("组选3");
                endIndex = responseStr.IndexOf("组选6");
                temp = responseStr.Substring(startIndex + 14, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.twoCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//二等奖个数
                startIndex = responseStr.IndexOf("组选6");
                temp = responseStr.Substring(startIndex + 14, 100);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.threeCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//三等奖个数
                startIndex = responseStr.IndexOf("投注总额");
                temp = responseStr.Substring(startIndex + 5, 50);  //截取内容  
                endIndex = temp.IndexOf("元");
                model.sumMoney = Convert.ToDecimal(temp.Substring(0, endIndex - 1).Trim(','));  //投注总额    
                model.oneMoney = 1040;
                model.twoMoney = 346;
                model.threeMoney = 173;
                model.LotteryType = lotteryType;
                if (model.sumMoney > 0)
                {
                    addWinInfo(model);
                }
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }
    }
    public void httpPost4(string url, int lotteryType)
    {

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*/*";
        request.Timeout = 50000;
        request.AllowAutoRedirect = false;

        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;

        try
        {
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Close();
            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                responseStr = reader.ReadToEnd();
                int startIndex = responseStr.IndexOf("codeshow");
                int endIndex = responseStr.IndexOf("</ul >");
                string LotteryNo = responseStr.Substring(startIndex + 11, endIndex - startIndex - 11);  //截取内容               
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "<[^>]+>", "");
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "&[^;]+;", "").Trim();
                model.LotteryNo = LotteryNo.Substring(0, 1) + "," + LotteryNo.Substring(1, 1) + "," + LotteryNo.Substring(2, 1) + "," + LotteryNo.Substring(3, 1) + "," + LotteryNo.Substring(4, 1);//中奖号码
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "<[^>]+>", "");
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "&[^;]+;", "").Trim();
                endIndex = responseStr.IndexOf("期");
                string temp = responseStr.Substring(7, endIndex - 7);  //截取内容         
                model.LotteryQS = temp;
                endIndex = responseStr.IndexOf("按期号查询");
                string openTime = responseStr.Substring(endIndex - 200, 300).Trim();
                startIndex = openTime.IndexOf("期");
                endIndex = openTime.IndexOf("按");
                openTime = openTime.Substring(startIndex + 1, endIndex - startIndex - 1).Trim();
                startIndex = openTime.IndexOf("(");
                string part1 = openTime.Substring(0, startIndex - 1).Trim();
                startIndex = openTime.IndexOf(")");
                string part2 = openTime.Substring(startIndex + 1).Trim();
                model.openTime = Convert.ToDateTime(part1 + " " + part2);//开奖时间
                startIndex = responseStr.IndexOf("一等奖");
                temp = responseStr.Substring(startIndex + 13, 100);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.oneCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//一等奖个数
                startIndex = responseStr.IndexOf("投注总额");
                temp = responseStr.Substring(startIndex + 5, 50);  //截取内容  
                endIndex = temp.IndexOf("元");
                model.sumMoney = Convert.ToDecimal(temp.Substring(0, endIndex - 1).Trim(','));  //投注总额   
                model.oneMoney = 1000;
                model.LotteryType = lotteryType;
                if (model.sumMoney > 0)
                {
                    addWinInfo(model);
                }
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }
    }
    public void httpPost5(string url, int lotteryType)
    {

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*/*";
        request.Timeout = 50000;
        request.AllowAutoRedirect = false;

        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;

        try
        {
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Close();
            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                responseStr = reader.ReadToEnd();
                int startIndex = responseStr.IndexOf("codeshow");
                int endIndex = responseStr.IndexOf("</ul >");
                string LotteryNo = responseStr.Substring(startIndex + 11, endIndex - startIndex - 11);  //截取内容               
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "<[^>]+>", "");
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "&[^;]+;", "").Trim();
                model.LotteryNo = LotteryNo.Substring(0, 1) + "," + LotteryNo.Substring(1, 1) + "," + LotteryNo.Substring(2, 1) + "," + LotteryNo.Substring(3, 1) + "," + LotteryNo.Substring(4, 1) + "," + LotteryNo.Substring(5, 1) + "," + LotteryNo.Substring(6, 1);//中奖号码
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "<[^>]+>", "");
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "&[^;]+;", "").Trim();
                endIndex = responseStr.IndexOf("期");
                string temp = responseStr.Substring(7, endIndex - 7);  //截取内容         
                model.LotteryQS = temp;
                endIndex = responseStr.IndexOf("按期号查询");
                string openTime = responseStr.Substring(endIndex - 200, 300).Trim();
                startIndex = openTime.IndexOf("期");
                endIndex = openTime.IndexOf("按");
                openTime = openTime.Substring(startIndex + 1, endIndex - startIndex - 1).Trim();
                startIndex = openTime.IndexOf("(");
                string part1 = openTime.Substring(0, startIndex - 1).Trim();
                startIndex = openTime.IndexOf(")");
                string part2 = openTime.Substring(startIndex + 1).Trim();
                model.openTime = Convert.ToDateTime(part1 + " " + part2);//开奖时间
                startIndex = responseStr.IndexOf("全中");
                endIndex = responseStr.IndexOf("二等奖");
                temp = responseStr.Substring(startIndex + 2, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.oneCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//一等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.oneMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("连续6位");
                endIndex = responseStr.IndexOf("三等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.twoCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//二等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.twoMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("连续5位");
                endIndex = responseStr.IndexOf("四等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.threeCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//三等奖个数
                startIndex = responseStr.IndexOf("连续4位");
                endIndex = responseStr.IndexOf("五等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fourCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//四等奖个数
                startIndex = responseStr.IndexOf("连续3位");
                endIndex = responseStr.IndexOf("六等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fiveCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//五等奖个数
                startIndex = responseStr.IndexOf("连续2位");
                temp = responseStr.Substring(startIndex + 4, 100);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.sixCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//六等奖个数
                startIndex = responseStr.IndexOf("投注总额");
                endIndex = responseStr.IndexOf("奖池累计");
                temp = responseStr.Substring(startIndex + 5, endIndex - startIndex - 8);  //截取内容  
                endIndex = temp.IndexOf("元");
                model.sumMoney = Convert.ToDecimal(temp.Substring(0, endIndex - 1).Trim(','));  //投注总额    
                startIndex = responseStr.IndexOf("奖池累计");
                string jiangChi = responseStr.Substring(startIndex + 5, 50);  //截取内容    
                endIndex = jiangChi.IndexOf("元");
                if (endIndex != -1)
                {
                    model.jiangChi = Convert.ToDecimal(jiangChi.Substring(0, endIndex - 1).Trim(','));  //截取内容  
                }
                else
                {
                    model.jiangChi = 0;
                }
                model.fourMoney = 300;
                model.fiveMoney = 20;
                model.sixMoney = 5;
                model.LotteryType = lotteryType;
                model.threeMoney = 1800;
                if (model.sumMoney > 0)
                {
                    addWinInfo(model);
                }
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }
    }
    public void httpPost6(string url, int lotteryType)
    {

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "*/*";
        request.Timeout = 50000;
        request.AllowAutoRedirect = false;

        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;

        try
        {
            Model.LotteryAnnouncement model = new Model.LotteryAnnouncement();
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Close();
            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                responseStr = reader.ReadToEnd();
                int startIndex = responseStr.IndexOf("codeshow");
                int endIndex = responseStr.IndexOf("</ul >");
                string LotteryNo = responseStr.Substring(startIndex + 11, endIndex - startIndex - 11);  //截取内容               
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "<[^>]+>", "");
                LotteryNo = System.Text.RegularExpressions.Regex.Replace(LotteryNo, "&[^;]+;", "").Trim();
                model.LotteryNo = LotteryNo.Substring(0, 2) + "," + LotteryNo.Substring(2, 2) + "," + LotteryNo.Substring(4, 2) + "," + LotteryNo.Substring(6, 2) + "," + LotteryNo.Substring(8, 2) + "," + LotteryNo.Substring(10, 2) + "," + LotteryNo.Substring(12, 2) + "+" + LotteryNo.Substring(14, 2);//中奖号码
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "<[^>]+>", "");
                responseStr = System.Text.RegularExpressions.Regex.Replace(responseStr, "&[^;]+;", "").Trim();
                endIndex = responseStr.IndexOf("期");
                string temp = responseStr.Substring(7, endIndex - 7);  //截取内容         
                model.LotteryQS = temp;
                endIndex = responseStr.IndexOf("按期号查询");
                string openTime = responseStr.Substring(endIndex - 200, 300).Trim();
                startIndex = openTime.IndexOf("期");
                endIndex = openTime.IndexOf("按");
                openTime = openTime.Substring(startIndex + 1, endIndex - startIndex - 1).Trim();
                startIndex = openTime.IndexOf("(");
                string part1 = openTime.Substring(0, startIndex - 1).Trim();
                startIndex = openTime.IndexOf(")");
                string part2 = openTime.Substring(startIndex + 1).Trim();
                model.openTime = Convert.ToDateTime(part1 + " " + part2);//开奖时间
                startIndex = responseStr.IndexOf("一等奖");
                endIndex = responseStr.IndexOf("二等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.oneCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//一等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.oneMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("二等奖");
                endIndex = responseStr.IndexOf("三等奖");
                temp = responseStr.Substring(startIndex + 6, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.twoCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//二等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.twoMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("三等奖");
                endIndex = responseStr.IndexOf("四等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.threeCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//三等奖个数
                temp = temp.Substring(endIndex + 3, temp.Length - endIndex - 4);
                startIndex = temp.IndexOf(")");
                endIndex = temp.IndexOf("元");
                model.threeMoney = Convert.ToDecimal(temp.Substring(startIndex + 1, endIndex - startIndex - 2).Trim(','));
                startIndex = responseStr.IndexOf("四等奖");
                endIndex = responseStr.IndexOf("五等奖");
                temp = responseStr.Substring(startIndex + 6, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fourCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//四等奖个数
                startIndex = responseStr.IndexOf("五等奖");
                endIndex = responseStr.IndexOf("六等奖");
                temp = responseStr.Substring(startIndex + 4, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.fiveCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//五等奖个数
                startIndex = responseStr.IndexOf("六等奖");
                endIndex = responseStr.IndexOf("七等奖");
                temp = responseStr.Substring(startIndex + 6, endIndex - startIndex);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.sixCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//六等奖个数
                startIndex = responseStr.IndexOf("七等奖");
                temp = responseStr.Substring(startIndex + 4, 100);  //截取内容               
                endIndex = temp.IndexOf("(");
                model.sevenCount = Convert.ToDecimal(temp.Substring(0, endIndex).Trim(','));//七等奖个数
                startIndex = responseStr.IndexOf("投注总额");
                endIndex = responseStr.IndexOf("奖池累计");
                temp = responseStr.Substring(startIndex + 5, endIndex - startIndex - 8);  //截取内容  
                endIndex = temp.IndexOf("元");
                model.sumMoney = Convert.ToDecimal(temp.Substring(0, endIndex - 1).Trim(','));  //投注总额    
                startIndex = responseStr.IndexOf("奖池累计");
                string jiangChi = responseStr.Substring(startIndex + 5, 50);  //截取内容    
                endIndex = jiangChi.IndexOf("元");
                if (endIndex != -1)
                {
                    model.jiangChi = Convert.ToDecimal(jiangChi.Substring(0, endIndex - 1).Trim(','));  //截取内容  
                }
                else
                {
                    model.jiangChi = 0;
                }
                model.fourMoney = 200;
                model.fiveMoney = 50;
                model.sixMoney = 10;
                model.sevenMoney = 5;
                model.LotteryType = lotteryType;
                if (model.sumMoney > 0)
                {
                    addWinInfo(model);
                }
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }
    }


    private static void addWinInfo(Model.LotteryAnnouncement model)
    {
        string sql = "select top 1 * from LotteryAnnouncement where LotteryType=" + model.LotteryType + " and lotteryQs=" + model.LotteryQS;
        if (BLL.LotteryQs.NewsTopOne(sql) == null)
        {
            model.AddTime = DateTime.Now;
            BLL.LotteryAnnouncement.Add(model);
        }

    }
</script>
